package middle;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

/**
 * MT18 重要节点
 * @author d3y1
 */
public class MT18{
    // 邻接节点
    private static HashSet<Integer>[] adj;
    // 入度
    private static int[] T;
    // 出度
    private static int[] S;

    public static void main(String[] args){
        Scanner in = new Scanner(System.in);

        while(in.hasNext()){
            solution(in);
        }
    }

    /**
     * 模拟法: bfs
     * @param in
     */
    private static void solution(Scanner in){
        int V = in.nextInt();
        int E = in.nextInt();

        adj = new HashSet[V+1];
        for(int i=1; i<=V; i++){
            adj[i] = new HashSet<>();
        }
        T = new int[V+1];
        S = new int[V+1];

        int u,v;
        for(int i=1; i<=E; i++){
            u = in.nextInt();
            v = in.nextInt();
            // 去环
            if(u != v){
                adj[u].add(v);
            }
        }

        for(int i=1; i<=V; i++){
            bfs(i);
        }

        int count = 0;
        for(int i=1; i<=V; i++){
            if(T[i] > S[i]){
                count++;
            }
        }

        System.out.println(count);
    }

    /**
     * 广度优先搜索
     * @param start
     * @return
     */
    private static void bfs(int start){
        HashSet<Integer> visited = new HashSet<>();
        Queue<Integer> queue = new LinkedList<>();

        visited.add(start);
        queue.offer(start);

        int size;
        while(!queue.isEmpty()){
            Integer u;
            size = queue.size();
            S[start] += size;
            for(int i=1; i<=size; i++){
                u = queue.poll();
                T[u]++;
                for(Integer v: adj[u]){
                    if(!visited.contains(v)){
                        visited.add(v);
                        queue.offer(v);
                    }
                }
            }
        }
    }
}